﻿<%@ Page Title="" Language="C#" MasterPageFile="~/manager/page/ManagerMasterPage.Master" AutoEventWireup="true" CodeBehind="newstore.aspx.cs" Inherits="Com.Web.coffinegurunaru.manager.store.newstore" %>
<%@ Register TagPrefix="UC" TagName="Menu" Src="~/manager/store/menu.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phHead" runat="server">
<SCRIPT type="text/javascript" src="http://openapi.map.naver.com/js/naverMap.naver?key=<%=NaverAPI.GetAPIKey()%>"></SCRIPT>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="phContent" runat="server">
<hr />
<br />
<table width="100%" border="0">
<tr>
	<td valign="top" width="60">
<UC:Menu ID="Menu1" SubPageType=3 runat="server" />
	</td>
	<td style="width:20px;"></td>
	<td valign="top">
		<table width="100%" height="100%" border="0">
		<tr>
			<td id="m_UserList" valign="top" width="560">
				[매장 리스트]
				<table cellpadding="0" cellspacing="1" style="background-color:Gray; width:400;" class="m_UserList">
				<tr>
					<td></td>
				</tr>
				</table>
				<table style="width:100%; height:30px;">
				<tr>
					<td style="text-align:center;"><div id="m_Pager"></div></td>
				</tr>
				</table>
			</td>
			<td style="width:10px;"></td>
			<td valign="top" id="m_NewOpenStore">
				<div class="m_StoreInfo"></div>
				<div id="m_MapContainer"></div>
				<div class="m_NewOpenStoreList"></div>
			</td>
		</tr>
		</table>
	</td>
</tr>
</table>

<script language="javascript" type="text/javascript">
(function($) {
	$.NewOpenStore = {};

	$.NewOpenStore = {
		PageNo : 1,
		
		
		Init : function() {
			$("#m_Pager").pager({
				pageSize : 20,
				useCallback : true,
				pageNo : 1,
				callback:function(pageNo) {
					$.NewOpenStore.StoreList();
				}
			});
			
			$.NewOpenStore.StoreList();
			$.NewOpenStore.OpenStoreList();
		},
		
		StoreList : function() {
			$("#m_UserList").ajaxNet(
			"/manager/store/storemethod.aspx?_vb=GetStoreSimpleList",
			{
				"IsActive": "Y"
			,	"PageNo": $("#m_Pager").pager("option", "currentPageNo")
			,	"PageSize": $("#m_Pager").pager("option", "pageSize")
			}, function(results, context) {
				$("#m_UserList>table.m_UserList>tbody").html($(results[0]))
					.find("input.m_btnNewOpenStore").click(function() {
						$(this).closest("tr").parent().find("tr:gt(0)").css({"background-color":"#ffffff"});
						$(this).closest("tr").css({"background-color":"#eeeeee"});
						$.NewOpenStore.StoreInfo( $(this).closest("tr") );
					});
				$("#m_Pager").pager("update", results[1]);
			});
		},
		
		StoreInfo : function( $tr )
		{
			$("#m_NewOpenStore div.m_NewOpenStoreList").hide();
			var UserID = $tr.find("td:eq(0)").text();
			var StoreNo = $tr.tagdata().StoreNo;
			$("#m_NewOpenStore div.m_StoreInfo").ajaxNet(
			"/manager/store/storemethod.aspx?_vb=GetOpenStoreInfo",
			{
				"StoreNo": StoreNo
			}, function(results, context) {
				$("#m_NewOpenStore div.m_StoreInfo").html( results );
				
				var $tbl = $("#m_NewOpenStore div.m_StoreInfo table")
				var data = $tbl.tagdata();
				var PointX, PointY;
				PointX = data.PointX;
				PointY = data.PointY
				
				if ( PointX != "" && PointY != "" )
					$.NewOpenStore.NaverMapViewr( data.PointX, data.PointY, $tbl.find("tr:eq(2) td:eq(1)").text() );	
				
				$("#m_NewOpenStore div.m_StoreInfo input.m_btnNewStoreCancel").click(function() {
					$("#m_MapContainer").hide();
					$("#m_NewOpenStore div.m_StoreInfo").html( "" );
					$("#m_NewOpenStore div.m_NewOpenStoreList").show();
				});
				
				$("#m_NewOpenStore div.m_StoreInfo input.m_btnNewStoreAdd").click(function() {
					
					var $tbl = $(this).closest("table");
					var data = $tbl.tagdata();
					
					$("#m_NewOpenStore div.m_StoreInfo").ajaxNet(
					"/manager/store/storemethod.aspx?_vb=AddBestStore",
					{
						"StoreNo": data.StoreNo
					}, function(results, context) {
						$.NewOpenStore.OpenStoreList();
						alert( "등록되었습니다.");
						location.href = location.href;
						$("#m_NewOpenStore div.m_StoreInfo").html( "" );
						$("#m_MapContainer").hide();
						//$("#m_NewOpenStore div.m_NewOpenStoreList").show();
					});
				});
			});
		},
		
		OpenStoreList : function() {
			$("#m_NewOpenStore div.m_NewOpenStoreList").ajaxNet(
			"/manager/store/storemethod.aspx?_vb=GetOpenStoreList",
			{
				"PageNo": 1
			,	"PageSize" : 20
			}, function(results, context) {
				$("#m_NewOpenStore div.m_NewOpenStoreList").html( results );
				
				$("#m_NewOpenStore div.m_NewOpenStoreList input.m_OpenStoreRemove").click(function() {
					if ( confirm("신규 오픈매장 리스트 삭제하시겠습니까?") )
					{
						var $tr = $(this).closest("tr");
						var StoreNo = $tr.tagdata().StoreNo;
						$tr.ajaxNet(
						"/manager/store/storemethod.aspx?_vb=RemoveBestStore",
						{
							"StoreNo": StoreNo
						}, function(results, context) {
							location.href = location.href;
							alert( "삭제되었습니다.");
							//$.NewOpenStore.OpenStoreList();
						});
					}
				});
			});
		},
		
		MapObj : null,
		markObj : null,
		infoWin : null,
		NaverMapViewr : function(PointX, PointY, address)
		{
			$("#m_MapContainer").show();
			var opts = {width:600, height:400, mapMode:0};
			var point = new NPoint(PointX,PointY);
			if ( $.NewOpenStore.MapObj != null )
			{
				$.NewOpenStore.MapObj.clearOverlays();
				$.NewOpenStore.MapObj.setCenter(point ,2);
			}
			else
			{
				$.NewOpenStore.MapObj = new NMap(document.getElementById('m_MapContainer'),opts);
				$.NewOpenStore.MapObj.setCenterAndZoom(point ,2);
			}
			
			/* 지도 컨트롤 생성 */
			var zoom = new NZoomControl();
			zoom.setAlign("left"); zoom.setValign("top");
			$.NewOpenStore.MapObj.addControl(zoom);

			/* 지도 좌표, 축적 수 준 초기화 */
			var iconURL = "/images/coffine.jpg";
			var iconSize = new NSize(30, 30);
			var icon = new NIcon(iconURL, iconSize)
			
			
			/* 지도 모드 변경 버튼 생성 */
			var mapBtns = new NMapBtns();
			mapBtns.setAlign("right"); mapBtns.setValign("top");
			$.NewOpenStore.MapObj.addControl(mapBtns);
			
			// 아이콘 표시 //
			$.NewOpenStore.markObj = new NMark(point, icon);
			$.NewOpenStore.MapObj.addOverlay( $.NewOpenStore.markObj );
			
			$.NewOpenStore.infowin = new NInfoWindow();
			$.NewOpenStore.MapObj.addOverlay($.NewOpenStore.infowin);
			NEvent.addListener($.NewOpenStore.markObj, "mouseover", function(pos) {
					$.NewOpenStore.infowin.set(pos, '<div style="width:100px; height:50px; background-color:#ffffff; border:solid 1px #666666;">' + address + '</div>');
					$.NewOpenStore.infowin.showWindow()
			});
			NEvent.addListener($.NewOpenStore.markObj, "mouseout", function() {
					$.NewOpenStore.infowin.hideWindow();
			});
		}
		
	}
	
	$(function() {
		$.NewOpenStore.Init();
	});
})(jQuery);

</script>
</asp:Content>
